﻿using System;
using WindowsService_Topshelf.Services;
using Topshelf;

namespace WindowsService_Topshelf
{
    class Program
    {
        /// <summary>
        /// 安装服务 命令行安装  这里要注意：必须使用管理员方式运行命令行窗口！！
        /// 安装服务 server.exe install
        /// 启动服务 server.exe start
        /// 停止服务 server.exe stop
        /// 卸载服务 server.exe uninstall
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            try
            {
                HostFactory.Run(x =>
                {
                    x.SetDescription("WindowsService_Topshelf测试服务");
                    x.SetDisplayName("WindowsService_Topshelf测试服务");
                    x.SetServiceName("WindowsService_Topshelf测试服务");
                    x.EnablePauseAndContinue();
                    x.Service<ServiceRunnerOne>();
                    Console.WriteLine("WindowsService_Topshelf测试服务注册完毕");
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("报错："+ex.Message);
            }

            Console.WriteLine("程序已运行结束，按任意键Enter退出");
            Console.ReadLine();
        }
    }
}
